from markdown import Markdown

md = Markdown(extensions=[
    'markdown.extensions.fenced_code',
    'markdown.extensions.md_in_html',
    'markdown.extensions.attr_list',
    'markdown.extensions.def_list',
    'markdown.extensions.footnotes',
    'markdown.extensions.tables',
    'markdown.extensions.admonition',
    'markdown.extensions.toc',
    'markdown.extensions.wikilinks',
    'markdown.extensions.sane_lists',
    'markdown.extensions.abbr',
    'mdx_math',
    # 'mdx_linkify',
    'markdown_svgbob',
    'nl2br',
])

def parse_md_page(page):
    md.reset()
    page = page.replace('\n${toc}\n', '\n[TOC]\n')
    page = md.convert(page)
    # if page.find('<p>::left::</p>') != -1:
    #     page = page.replace('<p>::left::</p>', '\n<div style="display: flex"><div style="margin-left: 5px; margin-right: 5px; flex: 1">\n')
    #     page = page.replace('<p>::right::</p>', '\n</div><div style="margin-left: 5px; margin-right: 5px; flex: 1">\n')
    #     if page.find('<p>::end::</p>') != -1:
    #         page = page.replace('<p>::end::</p>', '\n</div></div>\n')
    #     else:
    #         page += '\n</div></div>\n'
    return page
